/*
 * stack_monitor.c
 *
 *  Created on: Jul 17, 2021
 *      Author: dbw
 */

#include "stack_monitor.h"
#include "common.h"
#include <stdio.h>

extern int _sstack;
extern int _estack;

void stack_mnt_check(stack_info_t *info)
{
    uint8_t *begin_pos = (uint8_t *)&_sstack;
    uint8_t *end_pos = (uint8_t *)&_estack;

    info->total = end_pos - begin_pos;
    //TODO used
    info->used = 0;

    uint8_t *pos;
    for (pos = begin_pos; pos < end_pos && *pos == (uint8_t)'#'; pos++);
    info->max_used = end_pos - pos;
}

void stack_mnt_show(const char *desc)
{
    stack_info_t info;

    stack_mnt_check(&info);

    printf("%s, stack info: total:%lu, max_used:%lu\r\n",
            desc, info.total, info.max_used);
}
